<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            margin: 0;
        }
        #box{
            width: 400px;
            padding:15px;
            border:5px solid #eee;
        }
        span{
            background-color: #fc3;
        }
    </style>
</head>
<body>
    <div>
        <input type="text"><button>查找</button>
        <input type="text"><button>替换</button>
    </div>
    <div id="box">
        Lorem, ipsum dolor sit amet consectetur adipisicing elit. Blanditiis, cum facere! Delectus provident fuga, blanditiis quidem, at minima deserunt doloribus quam rem eum aut voluptatem quisquam nemo minus perspiciatis nostrum?
    </div>

    <script>
        let oFindText = document.getElementsByTagName('input')[0];
        let oFindBtn = document.getElementsByTagName('button')[0];
        let oReText = document.getElementsByTagName('input')[1];
        let oReBtn = document.getElementsByTagName('button')[1];
        let oBox = document.getElementById('box');
        // 记录旧内容
        let oldContent = oBox.innerHTML;

        oFindBtn.onclick = function(){
            let arr = oldContent.split(oFindText.value);
            oBox.innerHTML = arr.join(`<span>${oFindText.value}</span>`)
        }

        oReBtn.onclick = function(){
            let arr = oldContent.split(oFindText.value);
            oBox.innerHTML = arr.join(`${oReText.value}`);
            // 更新
            oldContent = oBox.innerHTML;
        }
    </script>
</body>
</html>